/** @file material.h
	@brief Material */

#ifndef G3_MATERIAL_H
#define G3_MATERIAL_H

#include "color.h"
#include "tex/tex_bitmap.h"
#include "res/res_shader_prog.h"
#include "res/res_texture.h"
#include "res/res_texture_mgr.h"
#include "lua_material.h"

#include <vector>

using namespace std;

namespace G3 {

/** @class MATERIAL
	@brief A material class */
class MATERIAL: public LOGGABLE {
	public:
        /**
            @brief Just a constructor that initializes the members
        */
		MATERIAL ();

		MATERIAL (const MATERIAL &mat);

        /** Material name */
		string name;

        /** Ambient color */
		COL4F ambient;
		/** Diffuse color */
		COL4F diffuse;
		/** Specular color */
		COL4F specular;
		/** Emission color - for lights */
		COL4F emission;

        /** Shininess factor 0..1 */
		float shininess;
		/** Reflectance factor 0..1 */
		float reflectance;

        /** A vector of texturemap handles */
		vector<H_TEXTURE> textures;
		/** A shader program class */
		SHADER_PROGRAM shader_program;

        /**
            @brief Assignment operator for copying materials
            @param[in] m Reference to the material to be copied
            @return Reference to the freshly copied material
        */
		MATERIAL& operator=(const MATERIAL &m);

        /**
            @brief Loads the material script from a stream
            @param[in] aStream Pointer to the stream
            @return True on success, false on failure
        */
		bool Load (STREAM *aStream);

        /**
            @brief Loads the material script from a file
            @param[in] aFilename The filename of that script
            @return True on success, false on failure
        */
		bool Load (const char *aFilename);

        /**
            @brief Applies the material to OpenGL renderer
        */
		void glApply ();

        /**
            @brief UnApplies the material from the OpenGL renderer
        */
		void glUnApply ();

        /**
            @brief Dumps the material
            \todo Dump attached shader program and textures as well
        */
		void dump ();
};

extern MATERIAL DefaultMaterial;

}

#endif //G3_MATERIAL_H

